<template>
  <div>
    <van-nav-bar
      title="选择影院"
      left-arrow
      fixed
      placeholder
      z-index="999"
      @click-left="$router.back()"
    />

    <van-cell-group>
      <van-cell :title="cityName" style="background: #f3f3f3" />

      <div v-if="status == 'loaded'">
        <van-cell
          v-for="item in shopList"
          :key="item._id"
          :title="item.name"
          :label="item.address"
          @click="chooseShop(item)"
        />
      </div>
      <div v-if="status == 'loading'" class="text-center" style="margin-top:50px">
        <van-loading type="spinner" />
      </div>

      <van-empty v-if="status == 'empty'" description="暂无数据" />
    </van-cell-group>
  </div>
</template>

<script>

export default {
  name: "shopList",
  data() {
    return {
      status: "loading",
    };
  },
  computed: {
    cityName() {
      return this.$route.query.cityName;
    },
  },
  created() {
    this.getShopList();
  },
  methods: {
    getShopList() {
      let { cityName } = this;
      this.$http
        .post("/apis/shop/pub/getList", {
          city: cityName,
        })
        .then((res) => {
          console.log(res);

          if (res.code == 0) {
            this.shopList = res.rows;

            if (this.shopList.length) {
              this.status = "loaded";
            } else {
              this.status = "empty";
            }
          }
        });
    },
    //  选择店铺
    chooseShop(item){
        console.log(item);
        let {name,_id} = item;

        // // localStorage 存起来都是字符串 
        localStorage.setItem('shopName',name)
        localStorage.setItem('shopId',_id)
        localStorage.setItem('shopInfo',JSON.stringify(item))  

        this.$router.push('/')


    }
  },
};
</script>

<style>
</style>